home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / dev / misc / FetchRefs1.3.lha / FetchRefs1.3 / Guide2AutoDoc / Guide2AutoDoc.c next >
Encoding:
C/C++ Source or Header  |  1995-08-21  |  1.9 KB  |  73 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. main()
  5. {
  6.     char in[260], out[260], *inptr, *outptr;
  7.  
  8.     /* Make it identifyable as an AutoDoc */
  9.     fputs("TABLE OF CONTENTS\n", stdout);
  10.  
  11.     /* Read the lines one by one. Compiler takes care of buffering. */
  12.     while (fgets(in, 255, stdin))
  13.     {
  14.         inptr = in;
  15.         outptr = out;
  16.  
  17.         if (strnicmp("@node", inptr, 5) == 0)
  18.         {
  19.             /* Transform a node into an AutoDoc title */
  20.             char name[80], *nameptr = name, quote;
  21.  
  22.             inptr += 5;
  23.  
  24.             while (*++inptr == ' ')
  25.                 ;
  26.             if (*inptr == '\"')
  27.                 inptr++, quote = 1;
  28.             else
  29.                 quote = 0;
  30.  
  31.             /* Copy name until quotation mark or space */
  32.             while ((*inptr != (quote ? '\"' : ' ')) && (*inptr != '\n'))
  33.                 if (inptr[0] == '(' && inptr[1] == ')')
  34.                     inptr += 2;
  35.                 else
  36.                     *nameptr++ = *inptr++;
  37.  
  38.             *nameptr = 0;
  39.  
  40.             fprintf(stdout, "%-37s%37s\n\n", name, name);
  41.         } else if (strnicmp("@endnode", inptr, 8) == 0)
  42.         {
  43.             /* End a node; an AutoDoc entry is ended by a form feed */
  44.             fputs("\f", stdout);
  45.         } else
  46.         {
  47.             /* Just a normal line */
  48.  
  49.             while (*inptr)
  50.             {
  51.                 if (inptr[0] == '@' && inptr[1] == '{' && inptr[2] == '\"')
  52.                 {
  53.                     inptr += 3;
  54.  
  55.                     /* Copy link text */
  56.                     while (*inptr != '\"')
  57.                         *outptr++ = *inptr++;
  58.                     /* Skip rest (actual link) */
  59.                     while (*inptr++ != '}')
  60.                         ;
  61.                 } else
  62.                     *outptr++ = *inptr++; /* Normal text - just copy */
  63.             }
  64.  
  65.             *outptr = 0;
  66.             fputs(out, stdout);
  67.         }
  68.     }
  69.  
  70.     return 0;
  71. }
  72.  
  73.